package ATM;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SaveJpanel extends JPanel implements ActionListener {
    private JButton btnOff;
    private JLabel jLabelSave;
    private JButton jButtonSave;
    private JTextField jTextFieldSave;
    private ATMJframe atmJframe;
    private Icon buttonSave = Util.getimagesIcon("/images/buttonSave.jpg");
    private Icon buttonOff = Util.getimagesIcon("/images/buttonOff.jpg");

    public SaveJpanel(ATMJframe atmJframe) {
        this.atmJframe = atmJframe;
        this.setLayout(null);
        this.setOpaque(false);
        jLabelSave = new JLabel("请输入存款金额：");
        jLabelSave.setBounds(300, 200, 250, 50);
        jLabelSave.setFont(new Font("宋体", Font.BOLD, 25));
        this.add(jLabelSave);

        jTextFieldSave = new JTextField();
        jTextFieldSave.setBounds(520, 200, 300, 50);
        jTextFieldSave.setFont(new Font("宋体", Font.BOLD, 25));
        this.add(jTextFieldSave);

        jButtonSave = new JButton("", buttonSave);
        jButtonSave.setBounds(300, 250, 140, 50);
        this.add(jButtonSave);
        jButtonSave.addActionListener(this);


        btnOff = new JButton("", buttonOff);
        btnOff.setBounds(850, 550, 140, 50);
        this.add(btnOff);
        btnOff.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnOff) {
            atmJframe.switchPanel("menu");
        } else if (e.getSource() == jButtonSave) {
            double a = Double.parseDouble(jTextFieldSave.getText());
            atmJframe.getUser().setCount(atmJframe.getUser().getCount() + a);
            JOptionPane.showMessageDialog(this, "存款成功,存入"+a+"元");
        }
        jTextFieldSave.setText("");
    }
}
